// pages/wdht/wdht.js
const app = getApp();
var common = require('../../utils/common.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    fylist: [],
    array: [{ "houseId": "", "name": "全部" }],
    index: 0,
    total: 0,
    page:1,
    houseId:"",
  },
  

  //选择房源
  bindPickerChange: function (e) {
    var that = this;
    var index = e.detail.value;
    var id = this.data.array[index].houseId;
    this.setData({
      fylist: [],
      index: index,
      page: 1,
      houseId:id,
    })
    console.log(id);
    this.getRoomsList(id);
    
  },

  getRoomsList: function (houseId) {
    var that = this;
    common._get('/wx/user/houselist', { page: this.data.page, houseId: houseId, status:1 },
      //成功
      function (res) {
        if (res.data.success) {
          console.log(res.data)
          if (res.data.data.list){
            that.data.page++;
            var temp = that.data.fylist.concat(res.data.data.list);
            that.setData({
              // fylist:res.data.data.list,
              fylist: temp,
              total: res.data.data.totalCount,
            })
          }
        }
      });
  },

  toDetail: function (e) {
    console.log();
    wx.navigateTo({
      url: '../waitingRentRoom/waitingRentRoom?room_id=' + e.currentTarget.dataset.roomid
    })
  },
  
  initData: function () {
    var that = this;
    //获取房源分组
    common._get('/wx/house/houselist', { page: 1, houseId: that.data.array[that.data.index].houseId },
      //成功
      function (res) {
        if (res.data.success) {
          console.log(res.data)
          var houseList = res.data.data.list;
          var newArray = that.data.array;
          for (var i in houseList) {
            var houseJson = {};
            houseJson["houseId"] = houseList[i].houseId;
            houseJson["name"] = houseList[i].houseName;
            newArray.push(houseJson);
          }
          that.setData({
            array: newArray
          })
        }
      });
    this.getRoomsList('');
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.initData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getRoomsList(this.data.houseId);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})